<?php
defined('_JEXEC') or die( 'Restricted access' );

jimport('joomla.application.component.model');

/**
 * @package		Joomla
 * @subpackage	Contact
 */
class UpdateservicesModelUpdateservices extends JModel
{
	var $db;
	function __construct(){
		$this->db = &JFactory::getDBO();
		parent::__construct();
	}
	
	function getList(){
		$user 	=& JFactory::getUser();
		if ( $user->get('guest')) {
			return;	
		}
		$userid=$user->id;
		$db = $this->db;
		$query = "SELECT * FROM #__services WHERE userid=".$db->Quote($userid);
		$db->setQuery($query);
		$row = $db->loadObjectList();
		return $row;
	}
	
	function saveList($arrfields, $userid){

		$db = $this->db;
		$db->setQuery("START TRANSACTION");
		$db->query();
		$query = "UPDATE #__services SET supported='0' WHERE userid=".$db->Quote($userid);
		$db->setQuery($query);
		$db->query();
		foreach($arrfields as $key=>$value){
			
			if($value!=""){
				$result = $this->update($value, $userid);
				if(!$result){
					break;	
				}
			}
		}
		if($result)
		{
			$db->setQuery("COMMIT");
			$result = $db->query();
		}
		else
		{
			$db->setQuery("ROLLBACK");
			$db->query();
		}	
	}
	
	function update($id, $userid){
		$db =  $this->db;
		$datetime = date("YmdHis");
		$query = "UPDATE #__services SET supported='1' WHERE id=".$db->Quote($id);
		$db->setQuery($query);
		return $db->query();
		
	}
}